package com.dailyblue.java.spring.rocketmq.过滤消息;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

public class 过滤消息的生产2 {
    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("zhuoyue01");
        producer.setNamesrvAddr("192.168.160.88:9876");
        producer.start();
        for (int i = 1; i < 21; i++) {
            String topic = "TopicA";
            String tags = "tag";
            int age = (int) (Math.random() * 100 + 1);
            Message message = new Message(topic, tags, ("index:" + i + ",age:" + age).getBytes(StandardCharsets.UTF_8));
            message.putUserProperty("age", age + "");
            producer.send(message);
        }
        producer.shutdown();
    }
}
